unit FiagSystem;

interface

uses DB, Classes, Registry, Windows;

function GetRegistryString(ARootKey: HKEY; ARegPath, AKeyName: string): string;
function GetDelphiRoot: string;
function GetBorlandSharedPath: string;
function TestConnection(AConnStr: string): Boolean;

procedure ViewDataSetForm(ADataSet: TDataSet);
procedure FocusNextComponent(Sender: TComponent);


implementation

uses SysUtils, Controls, ADODB, FormViewDataSet;

function GetRegistryString(ARootKey: HKEY; ARegPath, AKeyName: string): string;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := ARootKey;
    if Reg.OpenKey(ARegPath, False) then
      Result := Reg.ReadString(AKeyName)
    else
      raise Exception.Create('Could not get the path');
  finally
    Reg.CloseKey;
    Reg.Free;
  end;
end;

{ Function: Get Delphi Path}

function GetDelphiRoot: string;
const
  RootKey = HKEY_LOCAL_MACHINE;
  RegPath = '\SOFTWARE\Borland\BDS\3.0';
  KeyName = 'RootDir';
begin
  Result := GetRegistryString(RootKey, RegPath, KeyName);
end;

{ Function: Get Borland Shared Path}

function GetBorlandSharedPath: string;
const
  RootKey = HKEY_LOCAL_MACHINE;
  RegPath = '\SOFTWARE\Borland\Borland Shared';
  KeyName = 'SharedFilesDir';
begin
  Result := GetRegistryString(RootKey, RegPath, KeyName);
end;

function TestConnection(AConnStr: string): Boolean;
begin
  with TADOConnection.Create(nil) do
  begin
    ConnectionString := AConnStr;
    LoginPrompt := False;
    try
      Open;
      Result := Connected;
    except
      on E: Exception do
        Result := False;
    end;
    Close;
    Free;
  end;
end;

procedure ViewDataSetForm(ADataSet: TDataSet);
var
  fmViewDataSet: TfmViewDataSet;

begin
  fmViewDataSet := TfmViewDataSet.Create(ADataSet);
  fmViewDataSet.DataSet := ADataSet;
  fmViewDataSet.Show;
end;

procedure FocusNextComponent(Sender: TComponent);
var
  ATabOrder: TTabOrder;
  AWinControl: TWinControl;
  I, iCount: Integer;
begin
  ATabOrder := (Sender as TWinControl).TabOrder + 1;
  iCount := (Sender as TWinControl).Parent.ControlCount - 1;
  for I := 0 to iCount do
  begin
    if (Sender as TWinControl).Parent.Controls[I] is TWinControl then
    begin
      AWinControl := ((Sender as TWinControl).Parent.Controls[I] as
        TWinControl);
      if AWinControl.TabOrder = ATabOrder then
      begin
        AWinControl.SetFocus;
        Break;
      end;
    end;
  end;
end;


end.
